<template>
  <div class="homePage-content active-list-page">
    <div class="page-container">
      <!-- 面包屑导航 -->
      <div class="breadcrumb flex items-center mb-2 py-1 text-sm text-gray-500">
        <a href="/" class="text-gray-600 hover:text-primary transition-colors flex items-center">首页</a>
        <el-icon class="mx-2 text-xs">
          <ArrowRight />
        </el-icon>
        <a href="/information/informationList"
          class="text-gray-600 hover:text-primary transition-colors flex items-center">链主资讯</a>
        <el-icon class="mx-2 text-xs">
          <ArrowRight />
        </el-icon>
        <span class="text-gray-900 font-medium">正文</span>
      </div>
      <div class="main-layout">
        <!-- 左侧面板 -->
        <aside class="side-panel">
          <div class="brand-card">
            <img :src="chainEnterpriseDetail.logoUrl" :alt="chainEnterpriseDetail.enterpriseName"
              class="main-brand-logo">
            <h1 class="main-brand-name">{{ chainEnterpriseDetail.enterpriseName }}</h1>
            <el-popover :width="200" :trigger="trigger">
              <div class="brand-description">{{ chainEnterpriseDetail.introduction }}</div>
              <template #reference>
                <p class="brand-description line-clamp-3">{{ chainEnterpriseDetail.introduction }}</p>
              </template>
            </el-popover>
          </div>

          <div class="eco-section">
            <h2 class="section-title">核心生态伙伴</h2>
            <div class="eco-brand-logos">
              <div v-for="partner in chainEnterpriseDetail.partners" :key="partner.name" class="eco-brand-item">
                <img :src="partner.logoUrl" :alt="partner.partnerName">
                <span>{{ partner.partnerName }}</span>
              </div>
            </div>
          </div>

          <div class="subbrands-section eco-section">
            <h2 class="section-title">核心子品牌</h2>
            <div class="eco-brand-logos">
              <div v-for="subbrand in chainEnterpriseDetail.brands" :key="subbrand.brandName" class="eco-brand-item">
                <img :src="subbrand.logoUrl" :alt="subbrand.brandName">
                <span>{{ subbrand.brandName }}</span>
              </div>
            </div>
          </div>
        </aside>

        <!-- 主要内容区域 -->
        <main class="main-content">
          <section class="content-section">
            <h2 class="section-title">相关资讯</h2>
            <div class="tags-section cursor-pointer">
              <span v-for="tag in chainEnterpriseDetail.tagNames" :key="tag" class="tag">{{ tag }}</span>
            </div>
            <div class="article-grid">
              <article v-for="article in articles" :key="article.id" @click="goArticleDetails(article)"
                :class="['article-card', { featured: article.featured }]">
                <img :src="article.coverUrl" class="article-image" :alt="article.title">
                <div class="article-content">
                  <div :class="['article-tag', { 'featured-tag': article.featured }]">
                    {{ article.newsTypeName }}
                  </div>
                  <!-- <div class="article-source">{{ article.source }}</div> -->
                  <h3 class="article-title">{{ article.title }}</h3>
                  <p class="article-summary">{{ article.summary }}</p>
                  <div class="article-meta">
                    <DateConvert :date="article.publishTime" />
                    <!-- <span>{{ article.location }}</span> -->
                    <span>阅读 {{ article.viewCount }}次</span>
                  </div>

                </div>
              </article>
            </div>

            <!-- 分页控件 -->
            <div class="pagination">
              <div class="total">共{{ total }}项数据</div>
              <el-pagination style="justify-content: center" background layout="prev, pager, next" :total="total"
                v-model:current-page="params.pageNum" v-model:page-size="params.pageSize"
                @current-change="getEnterpriseNewsListFun" />
            </div>
          </section>
        </main>

        <!-- 右侧面板 -->
        <aside class="right-panel">
          <section class="timeline-section">
            <h2 class="section-title">全球化历程</h2>
            <div class="timeline">
              <div v-for="event in chainEnterpriseDetail.histories" :key="event.year" class="timeline-item">
                <div class="timeline-year">{{ event.year }}</div>
                <div class="timeline-content">{{ event.description }}</div>
              </div>
            </div>
          </section>
        </aside>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { getChainEnterpriseDetail, getEnterpriseNewsList } from '@/api/channel'
import { useRoute } from 'vue-router'
import { ArrowRight } from '@element-plus/icons-vue'
const route = useRoute()

const chainEnterpriseDetail = ref({})

// 根据路由里的id获取品牌详情
const getChainEnterpriseDetailFun = async () => {
  const res = await getChainEnterpriseDetail(route.query.id)
  if (res.suc) {
    chainEnterpriseDetail.value = res.data
  }
}

onMounted(() => {
  getChainEnterpriseDetailFun()
  getEnterpriseNewsListFun()
})


const goArticleDetails = (article) => {
  console.log(article)
  // 新打开一个页面
  window.open(`/channel/linkInformationDetails?id=${article.id}&enterpriseId=${route.query.id}`, '_blank')
}

const params = ref({
  "pageNum": 1,
  "pageSize": 10,
  "enterpriseId": route.query.id
})

const total = ref(0)

const getEnterpriseNewsListFun = async () => {
  const res = await getEnterpriseNewsList(params.value)
  if (res.suc) {
    articles.value = res.data.list;
    total.value = res.data.total
  }
}

// 文章数据
const articles = ref([])

// 分页相关
const currentPage = ref(1)
const totalPages = ref(10)
const showDots = computed(() => totalPages.value > 5)

const changePage = (page) => {
  currentPage.value = page
}

const nextPage = () => {
  if (currentPage.value < totalPages.value) {
    currentPage.value++
  }
}
</script>

<style scoped>
.page-container {
  --primary-color: #4A6BDF;
  --secondary-color: #29d;
  --accent-color: #ff6b6b;
  --text-primary: #333;
  --text-secondary: #666;
  --text-light: #888;
  --bg-white: #fff;
  --bg-light: #f8f9ff;
  --bg-gray: #f5f7fa;
  --border-color: #eee;
  --border-radius: 12px;
  --spacing-unit: 8px;
  --transition-normal: all 0.3s ease;
  --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --primary-light: rgba(74, 107, 223, 0.1);

  min-height: 100vh;
  /* background: var(--bg-light); */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  margin-bottom: 10px;
  border-radius: 10px;
}

.page-header {
  background: var(--bg-white);
  padding: calc(var(--spacing-unit) * 2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.main-layout {
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  max-width: 1200px;
  margin: calc(var(--spacing-unit) * 1.5) auto;
  gap: calc(var(--spacing-unit) * 1.5);
}

.side-panel {
  align-self: flex-start;
  height: fit-content;
}

.brand-card {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: calc(var(--spacing-unit) * 2);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  text-align: center;
  margin-bottom: calc(var(--spacing-unit) * 1.5);
}

.main-brand-logo {
  width: 100px;
  height: 100px;
  border-radius: var(--border-radius);

  margin: 0 auto;
  margin-bottom: calc(var(--spacing-unit) * 2);
  object-fit: contain;
  background: var(--bg-white);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.main-brand-name {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: var(--spacing-unit);
}

.brand-description {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.eco-section {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: calc(var(--spacing-unit) *1.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  margin-bottom: calc(var(--spacing-unit) * 1.5);
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: calc(var(--spacing-unit));
  position: relative;
  padding-bottom: 10px;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 40px;
  height: 3px;
  background: var(--primary-color);
  border-radius: 3px;
}

.eco-brand-logos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--spacing-unit));
}

.eco-brand-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  transition: var(--transition-normal);
  padding: calc(var(--spacing-unit));
  border-radius: var(--border-radius);
  background: var(--bg-light);
  cursor: pointer;
}

.eco-brand-item:hover {
  transform: translateY(-2px);
  background: var(--bg-white);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.eco-brand-item img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  margin-bottom: var(--spacing-unit);
  object-fit: contain;
  background: var(--bg-white);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.eco-brand-item span {
  font-size: 12px;
  color: var(--text-secondary);
  word-wrap: break-word;
  word-break: break-all;
  text-align: center;
  width: 100%;
  line-height: 1.2;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.main-content {
  min-width: 0;
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: calc(var(--spacing-unit) * 2);
  box-shadow: var(--box-shadow);
}

.content-section {
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.tags-section {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing-unit) * 1.2);
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.tag {
  padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1.8);
  background: var(--bg-light);
  border-radius: 20px;
  color: var(--primary-color);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition-normal);
  border: 1px solid rgba(74, 107, 223, 0.12);
}

.tag:hover {
  background: var(--primary-color);
  color: var(--bg-white);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(42, 81, 202, 0.15);
}

.article-grid {
  display: grid;
  grid-template-columns: 1fr;
  /* gap: 24px; */
}

.article-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  transition: all 0.25s ease;
  min-height: 130px;
  border: 1px solid rgba(0, 0, 0, 0.02);
  margin-bottom: 14px;
  position: relative;
}

.article-card:hover {
  box-shadow: 0 4px 12px rgba(42, 81, 202, 0.08);
  transform: translateY(-1px);
  border-color: rgba(74, 107, 223, 0.05);
}

.article-image {
  width: 140px;
  aspect-ratio: 1/1;
  object-fit: cover;
  border-radius: 8px 0 0 8px;
  background: #f5f7fa;
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.article-content {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  flex: 1;
}

.article-title {
  font-size: 16px;
  font-weight: 600;
  color: #222;
  margin: 0 0 8px 0;
  line-height: 1.4;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.2s;
  cursor: pointer;
}

.article-tag {
  display: inline-block;
  background: rgba(74, 107, 223, 0.08);
  color: var(--primary-color);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.featured-tag {
  background: linear-gradient(45deg, #4A6BDF, #29d);
  color: white;
}

.article-meta {
  font-size: 12px;
  color: #888;
  margin-top: 6px;
  margin-bottom: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.article-meta span {
  position: relative;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.article-summary {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-source {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 10px;
  color: #a8a8a8;
  background: rgba(255, 255, 255, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 1;
}

.right-panel {
  position: sticky;
  top: 80px;
  align-self: flex-start;
  min-width: 0;
  height: fit-content;
}

.timeline-section {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: calc(var(--spacing-unit) * 2);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.timeline {
  position: relative;
  padding-left: calc(var(--spacing-unit) * 3);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: #5C7AE2;
}

.timeline-item {
  position: relative;
  padding-bottom: calc(var(--spacing-unit) * 3);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: calc((var(--spacing-unit) * -3) - 5px);
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary-color);
  border: 3px solid var(--bg-white);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.timeline-year {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: var(--spacing-unit);
}

.timeline-content {
  color: var(--text-secondary);
  line-height: 1.4;
  font-size: 14px;
}

.pagination {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pagination-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.pagination-btn.active,
.pagination-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.pagination-dots {
  color: var(--text-secondary);
}

.pagination-next {
  padding: 0 16px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-next:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* 响应式布局 */
@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 260px 1fr 300px;
  }
}

@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    gap: calc(var(--spacing-unit) * 3);
  }

  .side-panel,
  .right-panel {
    position: static;
    top: auto;
  }

  .right-panel {
    margin-top: 0;
  }
}

@media (max-width: 768px) {

  .content-section,
  .timeline-section {
    padding: calc(var(--spacing-unit) * 2);
  }

  .article-grid {
    grid-template-columns: 1fr;
  }

  .article-image {
    width: 140px;
    aspect-ratio: 1/1;
  }

  .article-content {
    padding: 12px 16px;
  }

  .article-title {
    font-size: 15px;
    margin-bottom: 6px;
  }

  .article-meta {
    font-size: 12px;
    gap: 10px;
    margin-bottom: 4px;
  }

  .article-meta span:not(:first-child)::before {
    left: -6px;
  }

  .article-summary {
    font-size: 13px;
    -webkit-line-clamp: 2;
  }

  .article-source {
    top: 8px;
    right: 8px;
    font-size: 9px;
    padding: 1px 4px;
  }
}

@media (max-width: 700px) {
  .article-card {
    flex-direction: row;
    min-height: 120px;
  }

  .article-image {
    width: 120px;
    aspect-ratio: 1/1;
    border-radius: 8px 0 0 8px;
  }

  .article-content {
    padding: 10px 12px;
  }

  .article-summary {
    -webkit-line-clamp: 1;
  }

  .article-source {
    display: none;
  }
}

@media (max-width: 480px) {
  .article-summary {
    display: none;
  }

  .article-card {
    min-height: 100px;
  }

  .article-image {
    width: 100px;
  }

  .article-content {
    padding: 8px 10px;
  }

  .article-title {
    font-size: 14px;
    margin-bottom: 4px;
  }

  .article-meta {
    font-size: 11px;
    gap: 8px;
  }

  .brand-stats {
    grid-template-columns: 1fr;
  }

  .eco-brand-logos {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 交互效果 */
.article-card:hover .article-title {
  color: var(--primary-color);
}

.article-card:hover .article-image {
  filter: brightness(1.02);
}
</style>
